$(function(){
	
	var supplierId = $(".supplierId").val();
	var warehouseId;
	var cartGoods;
	
	
	$('.datepicker').datepicker({
	     format: "yyyy-mm-dd",
	     language: "zh-CN",
	     orientation: "top left",
	     autoclose:true
	});
	var dataTable = $('#supplierGoods').dataTable({
		"ColumnDefs" : [ {
	        sDefaultContent : '',
	        aTargets : [ '_all' ]
		} ],
		bFilter: false,
		"bPaginate": false,
        aaData: [],
        aoColumns: [
            {mDataProp:"taosku"},
            {mDataProp:"bn"},
            {mDataProp:"name"},
            {mDataProp:"deliveryNum"},
            {mDataProp:"availableNum"},
            {mDataProp:"saleNumPerWeek"},
            {mDataProp:"salePrice"},
            {mDataProp:"recentPurchasePrice"},
            {mDataProp:"purchasePrice"},
            {mDataProp:"discountRate"},
            {mDataProp:"taxRate"},
            {mDataProp:"sizeSpec"},
            {mDataProp:"purchaseNum"},
            {mDataProp:"totalAmount"},
            {mDataProp:"goodsId"},
            {mDataProp:"goodsSpecId"}
        ],
        columnDefs:[{
        	targets:[8],
        	data:"purchasePrice",
        	render: function(data, type, full) {
                return "<input type='text' class='price userEdit' value="+ data+">";
            }
        },
        {
        	targets:[9],
        	data:"discountRate",
        	render: function(data, type, full) {
                return "<input type='text' class='rate userEdit' value='100'>";
            }
        } ,
        {
        	targets:[12],
        	data:"purchaseNum",
        	render: function(data, type, full) {
                return "<input type='text' class='buyAmount userEdit'  value=0>";
            }
        },
        {
        	targets:[13],
        	data:"totalAmount",
        	sClass:'amount',
        },
        {
        	targets:[14],
        	"bVisible": false,
        	data:"goodsId",
        },
        {
        	targets:[15],
        	"bVisible": false,
        	data:"goodsSpecId",
        }]
    } );
	
	$.getJSON("/po_purchase/view?orderId="+GetQueryString("orderId"),null,function(data){
		console.log(data);
	});
	function RefreshTable(tableId, urlData)
    {
      //Retrieve the new data with $.getJSON. You could use it ajax too
      $.getJSON(urlData, null, function( json )
      {
        table = $(tableId).dataTable();
        oSettings = table.fnSettings();

        table.fnClearTable(this);

        for (var i=0; i<json.data.length; i++)
        {
          table.oApi._fnAddData(oSettings, json.data[i]);
        }

        oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
        table.fnDraw();
      });
    }
	
	function GetQueryString(name) {
		var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
		var r = window.location.search.substr(1).match(reg);
		if (r != null)
			return (r[2]);
		return "";
	}
});
